package com.zhouchao.mvp2.login;

import com.zhouchao.mvp2.entity.User;

import java.util.Random;

/**
 * 描述：
 * zhougan
 * 2019/2/28
 **/
public class LoginModel implements LoginContract.ILoginModel {
    @Override
    public void login(User user, final Callback callback) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(4000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                int i= new Random().nextInt(3);
                if(i==1){
                    callback.onLoginFailure("登陆失败");
                }else{
                    callback.onLoginSuccess();

                }

            }
        }).start();


    }

    @Override
    public String invalidate(User user) {
        if (user == null) {
            return "user 不能为null";
        }
        if ("".equals(user.getName()) || user.getName() == null) {
            return "用户名不能为空";

        }
        if ("".equals(user.getPwd()) || user.getPwd() == null) {
            return "密码不能为空";
        }

        return INVALIDATE_SUCCESS;
    }
}
